package com.hzt.business.controller;

import com.hzt.business.domain.Inport;
import com.hzt.business.service.InportService;
import com.hzt.business.vo.InportVo;
import com.hzt.system.common.ActiveUser;
import com.hzt.system.common.Constant;
import com.hzt.system.common.DataGridView;
import com.hzt.system.common.ResultObj;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.imageio.ImageIO;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
* 
* 
* @Author:hzt
* @Date:6:52 下午 2020/7/25
*/
@RequestMapping("api/inport")
@RestController
public class InportController {

    @Autowired
    private InportService inportService;

    @RequestMapping("loadAllInport")
    public Object loadAllInport(InportVo inportVo){
        return this.inportService.queryAllInport(inportVo);
    }


    @RequestMapping("addInport")
    public ResultObj addInport(Inport inport){

        try {
            ActiveUser activeUser = (ActiveUser) SecurityUtils.getSubject().getPrincipal();
            String name = activeUser.getUser().getName();
            inport.setOperateperson(name);
            inport.setInporttime(new Date());
            inportService.saveInport(inport);
            return  ResultObj.ADD_SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            return  ResultObj.ADD_SUCCESS;
        }
    }


    @RequestMapping("updateInport")
    public ResultObj updateInport(Inport inport){
        try {
            inportService.updateInport(inport);
            return ResultObj.UPDATE_SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            return ResultObj.UPDATE_ERROR;
        }
    }


    @RequestMapping("deleteInport")
    public ResultObj deleteInport(Inport inport){
        try {
            inportService.removeById(inport.getId());
            return ResultObj.DELETE_SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            return ResultObj.DELETE_ERROR;
        }
    }




}
